# -*— coding: utf-8 -*-
# @Time: 2024/6/20 14:39
# @Author :Lin Zhou
# @Email : lin1013143@163.com
# @File : form_data_utils.py
# @SoftWare: PyCharm
import json
import random
import string
import uuid


def post_assemble_form_data(data):
    """
    手动拼接form-data格式请求
    :param data:
    :return:
    """
    body = ""
    boundary = generate_boundary()
    for key, value in data.items():
        body += f"--{boundary}\r\n"
        body += f"Content-Disposition: form-data; name=\"{key}\"\r\n\r\n"
        body += f"{value}\r\n"
    body += f"--{boundary}--\r\n"  # 结束边界，带有两个连字符
    return body, boundary


def generate_boundary():
    return '--------------------' + str(uuid.uuid4())
